package com.kuang.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author Niddles
 * @create 2021：05:26:10:35
 * @Theme default
 */
public class privilegeInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //逻辑说明：在session中获取属性attribute为user的，如果
        //没有则就是没有登陆，就重定向到登陆页面，如果有就放行到主页面。
        HttpSession httpSession = request.getSession();
        Object user = httpSession.getAttribute("user");
        if (user==null){
            response.sendRedirect(request.getContextPath()+"/login.jsp");
        }
        return true;
    }


}
